package com.iflyings.android.convention

import com.android.build.api.dsl.CommonExtension
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.getByType

internal fun Project.configureAndroidJni(
    commonExtension: CommonExtension<*, *, *, *>,
) {
    val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")

    commonExtension.apply {

        defaultConfig {
            externalNativeBuild {
                cmake {
                    cppFlags("-fexceptions", "-frtti")
                    abiFilters("armeabi-v7a", "arm64-v8a")
                }
            }
        }

        externalNativeBuild {
            cmake {
                path("src/main/cpp/CMakeLists.txt")
                version = libs.findVersion("cmakeVersion").get().toString()
            }
        }

        ndkVersion = libs.findVersion("ndkVersion").get().toString()
    }
}
